package com.antball.aaa.command_responsibilitychain_design.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @Auther: huangsj
 * @Date: 2019/8/6 17:47
 * @Description:
 */
public class CommandVo {

    public final static String DILIDE_FLAG = " ";

    //参数前的符号
    public final static String PREPIX = "-";

    private String commanName="";

    private List<String> paramList=new ArrayList<String>();
    private List<String> optionList=new ArrayList<String>();

    public CommandVo(String commandStr){
        if(commandStr!=null && commandStr.length()>0){
            //拆分出执行符号
            String [] complexStr= commandStr.split(DILIDE_FLAG);

            //第一个参数为命令
            this.commanName = complexStr[0];

            for(int i=1;i<complexStr.length;i++){
                String tmp = complexStr[i];
                if(tmp.indexOf(PREPIX)==0){
                    paramList.add(tmp.replace(PREPIX,"").trim());
                }else{
                    optionList.add(tmp.trim());
                }
            }
        }
    }

    public String getCommanName() {
        return commanName;
    }

    public List<String> getOptionList() {
        return optionList;
    }

    public List<String> getParamList() {
        if(paramList.size()>0){
            return new ArrayList<String>(new HashSet<String>(this.paramList));
        }
        return paramList;
    }
}
